//
//  TabbarView.m
//  ShiShiQiuSai_NBA
//
//  Created by 张宁宁 on 2018/1/22.
//  Copyright © 2018年 all. All rights reserved.
//

#import "TabbarView.h"


@interface TabBarView (){
    
    UIButton                                              *mainButton;
    UIButton                                              *workButton;
    UIButton                                              *noticeButton;
    UIButton                                              *myButton;
    
    UIImageView                                           *mainimage;
    UIImageView                                           *workimage;
    UIImageView                                           *noticeimage;
    UIImageView                                           *myImage;
    
    UILabel                                               *main;
    UILabel                                               *work;
    UILabel                                               *notice;
    UILabel                                               *my;
    
}

@end

#define nomalColor RGBColor(155,155,155)

#define selectColor RGBColor(35,62,74)

@implementation TabBarView

@synthesize tabbarDelegate;

- (id)initWithFrame:(CGRect)frame {
    if ((self = [super initWithFrame:frame])) {
        //主页
        mainButton = [UIButton buttonWithType:UIButtonTypeCustom];
        mainButton.backgroundColor = BackViewWhiteColor;
        mainButton.frame=CGRectMake(0, 0, SCREEN_WIDTH/4, [UIView getSuitableLength:49]);
        [mainButton addTarget:self action:@selector(butttonSelect:) forControlEvents:UIControlEventTouchUpInside];
        
        mainimage = [[UIImageView alloc]init];
        mainimage.frame = CGRectMake(SCREEN_WIDTH/4/2-[UIView getSuitableLength:25]/2, [UIView getSuitableLength:49-34]/2, [UIView getSuitableLength:25], [UIView getSuitableLength:25]);
        [mainimage setImage:[UIImage imageNamed:@"ic_home_normal"]];
        [mainButton addSubview:mainimage];
        
        
        main = [[UILabel alloc]init];
        main.text = @"首页";
        main.frame = CGRectMake(0, [mainimage getViewYHeight], SCREEN_WIDTH/4, [UIView getSuitableLength:14]);
        main.font = FontWithName(10);
        main.textColor = selectColor;
        main.textAlignment = NSTextAlignmentCenter;
        [mainButton addSubview:main];
        mainButton.tag = 0;
        [mainButton setSelected:YES];
        [self addSubview:mainButton];
        
        
        //消息
        noticeButton = [UIButton buttonWithType:UIButtonTypeCustom];
        noticeButton.backgroundColor = BackViewWhiteColor;
        noticeButton.frame = CGRectMake(SCREEN_WIDTH/4, 0, SCREEN_WIDTH/4, [UIView getSuitableLength:49]);
        [noticeButton addTarget:self action:@selector(butttonSelect:) forControlEvents:UIControlEventTouchUpInside];
        
        noticeimage = [[UIImageView alloc]init];
        noticeimage.frame = CGRectMake(SCREEN_WIDTH/4/2-25/2, [UIView getSuitableLength:49-34]/2, [UIView getSuitableLength:25], [UIView getSuitableLength:25]);
        noticeimage.frame = CGRectMake(SCREEN_WIDTH/4/2-[UIView getSuitableLength:25]/2, [UIView getSuitableLength:49-34]/2, [UIView getSuitableLength:25], [UIView getSuitableLength:25]);
        [noticeimage setImage:[UIImage imageNamed:@"ic_message_normal"]];
        [noticeButton addSubview:noticeimage];
        notice = [[UILabel alloc]init];
        notice.text = @"消息";
        notice.frame = CGRectMake(0, [noticeimage getViewYHeight], SCREEN_WIDTH/4, [UIView getSuitableLength:14]);
        notice.font = FontWithName(10);
        notice.textColor = nomalColor;
        notice.textAlignment = NSTextAlignmentCenter;
        [noticeButton addSubview:notice];
        noticeButton.tag = 1;
        [self addSubview:noticeButton];
        
        //工作台
        workButton =[UIButton buttonWithType:UIButtonTypeCustom];
        workButton.backgroundColor = BackViewWhiteColor;
        workButton.frame = CGRectMake(SCREEN_WIDTH/4*2, 0, SCREEN_WIDTH/4, [UIView getSuitableLength:49]);
        [workButton addTarget:self action:@selector(butttonSelect:) forControlEvents:UIControlEventTouchUpInside];
        workimage = [[UIImageView alloc]init];
        
        workimage.frame = CGRectMake(SCREEN_WIDTH/4/2-[UIView getSuitableLength:25]/2,[UIView getSuitableLength:49-34]/2, [UIView getSuitableLength:25], [UIView getSuitableLength:25]);
        [workimage setImage:[UIImage imageNamed:@"ic_gzt_normal"]];
        [workButton addSubview:workimage];
        work = [[UILabel alloc]init];
        work.text = @"工作台";
        work.frame = CGRectMake(0, [workimage getViewYHeight], SCREEN_WIDTH/4, [UIView getSuitableLength:14]);
        work.font = FontWithName(10);
        work.textColor = nomalColor;
        work.textAlignment = NSTextAlignmentCenter;
        [workButton addSubview:work];
        workButton.tag = 2;
        [self addSubview:workButton];
        
        //个人中心
        myButton =[UIButton buttonWithType:UIButtonTypeCustom];
        myButton.backgroundColor = BackViewWhiteColor;
        myButton.frame = CGRectMake(SCREEN_WIDTH/4*3, 0, SCREEN_WIDTH/4, [UIView getSuitableLength:49]);
        [myButton addTarget:self action:@selector(butttonSelect:) forControlEvents:UIControlEventTouchUpInside];
        myImage = [[UIImageView alloc]init];
        
        myImage.frame = CGRectMake(SCREEN_WIDTH/4/2-[UIView getSuitableLength:25]/2, [UIView getSuitableLength:49-34]/2, [UIView getSuitableLength:25], [UIView getSuitableLength:25]);
        [myImage setImage:[UIImage imageNamed:@"ic_user_normal"]];
        [myButton addSubview:myImage];
        my = [[UILabel alloc]init];
        my.text = @"个人中心";
        my.frame = CGRectMake(0, [myImage getViewYHeight], SCREEN_WIDTH/4, [UIView getSuitableLength:14]);
        my.font = FontWithName(10);
        my.textColor = nomalColor;
        my.textAlignment = NSTextAlignmentCenter;
        [myButton addSubview:my];
        myButton.tag = 3;
        [self addSubview:myButton];
        
    }
    return self;
}

#pragma mark -
#pragma mark delegateMethod
- (void)butttonSelect:(UIButton *)sender {
    if (tabbarDelegate  != nil && [tabbarDelegate respondsToSelector:@selector(tabBarSelected:)]) {
        [tabbarDelegate tabBarSelected:sender.tag];
        switch (sender.tag) {
            case 0:
                [mainimage setImage:[UIImage imageNamed:@"ic_home_press"]];
                [noticeimage setImage:[UIImage imageNamed:@"ic_message_normal"]];
                [workimage setImage:[UIImage imageNamed:@"ic_gzt_normal"]];
                [myImage setImage:[UIImage imageNamed:@"ic_user_normal"]];
                
                main.textColor = selectColor;
                work.textColor = nomalColor;
                notice.textColor = nomalColor;
                my.textColor = nomalColor;
                break;
            case 1:
                [mainimage setImage:[UIImage imageNamed:@"ic_home_normal"]];
                [noticeimage setImage:[UIImage imageNamed:@"ic_message_press"]];
                [workimage setImage:[UIImage imageNamed:@"ic_gzt_normal"]];
                [myImage setImage:[UIImage imageNamed:@"ic_user_normal"]];
                main.textColor = nomalColor;
                notice.textColor = selectColor;
                work.textColor = nomalColor;
                my.textColor = nomalColor;
                break;
            case 2:
                [mainimage setImage:[UIImage imageNamed:@"ic_home_normal"]];
                [noticeimage setImage:[UIImage imageNamed:@"ic_message_normal"]];
                [workimage setImage:[UIImage imageNamed:@"ic_gzt_press"]];
                [myImage setImage:[UIImage imageNamed:@"ic_user_normal"]];
                main.textColor = nomalColor;
                notice.textColor = nomalColor;
                work.textColor = selectColor;
                
                my.textColor = nomalColor;
                break;
            case 3:
                [mainimage setImage:[UIImage imageNamed:@"ic_home_normal"]];
                [workimage setImage:[UIImage imageNamed:@"ic_gzt_normal"]];
                [noticeimage setImage:[UIImage imageNamed:@"ic_message_normal"]];
                [myImage setImage:[UIImage imageNamed:@"ic_user_press"]];
                main.textColor = nomalColor;
                work.textColor = nomalColor;
                notice.textColor = nomalColor;
                my.textColor = selectColor;
                break;
            default:
                break;
        }
    }
}

- (void)setCurrentIndex:(NSInteger)currentIndex {
    if (tabbarDelegate  != nil && [tabbarDelegate respondsToSelector:@selector(tabBarSelected:)]) {
        [tabbarDelegate tabBarSelected:currentIndex];
        switch (currentIndex) {
            case 0:
                [mainimage setImage:[UIImage imageNamed:@"ic_home_press"]];
                [noticeimage setImage:[UIImage imageNamed:@"ic_message_normal"]];
                [workimage setImage:[UIImage imageNamed:@"ic_gzt_normal"]];
                [myImage setImage:[UIImage imageNamed:@"ic_user_normal"]];
                
                main.textColor = selectColor;
                work.textColor = nomalColor;
                notice.textColor = nomalColor;
                my.textColor = nomalColor;
                break;
            case 1:
                [mainimage setImage:[UIImage imageNamed:@"ic_home_normal"]];
                [noticeimage setImage:[UIImage imageNamed:@"ic_message_press"]];
                [workimage setImage:[UIImage imageNamed:@"ic_gzt_normal"]];
                [myImage setImage:[UIImage imageNamed:@"ic_user_normal"]];
                main.textColor = nomalColor;
                notice.textColor = selectColor;
                work.textColor = nomalColor;
                my.textColor = nomalColor;
                break;
            case 2:
                [mainimage setImage:[UIImage imageNamed:@"ic_home_normal"]];
                [noticeimage setImage:[UIImage imageNamed:@"ic_message_normal"]];
                [workimage setImage:[UIImage imageNamed:@"ic_gzt_press"]];
                [myImage setImage:[UIImage imageNamed:@"ic_user_normal"]];
                main.textColor = nomalColor;
                notice.textColor = nomalColor;
                work.textColor = selectColor;
                
                my.textColor = nomalColor;
                break;
            case 3:
                [mainimage setImage:[UIImage imageNamed:@"ic_home_normal"]];
                [workimage setImage:[UIImage imageNamed:@"ic_gzt_normal"]];
                [noticeimage setImage:[UIImage imageNamed:@"ic_message_normal"]];
                [myImage setImage:[UIImage imageNamed:@"ic_user_press"]];
                main.textColor = nomalColor;
                work.textColor = nomalColor;
                notice.textColor = nomalColor;
                my.textColor = selectColor;
                break;
            default:
                break;
        }
    }
}

@end

